Python, VS Code, and Git





Kerry Back

Installing python

  • Install from python.org or anaconda.com. I use python.org but either will work.
  • Differences:
    • anaconda installs IDEs: JupyterLab, Spyder, PyCharm
    • anaconda installs scientific packages: numpy, pandas, statsmodels, scipy, jupyter, …
    • package manager: conda vs. pip
  • Either way, add python to your path.

Installing VS Code

  • VS Code is an IDE (integrated development environment)
  • VS Code is short for Visual Studio Code.
    • Visual Studio is for .NET and C++ developers. We don’t need it.
    • Visual Studio Code is a stand-alone and much smaller product.
  • There are alternatives, but I like VS Code.

VS Code Extensions

After installing VS Code, google in a browser to find the VS Code Marketplace (or click the Extensions icon on the left panel in VS Code) and install these extensions:

  • Python
  • ChatGpt4 (by bito)
  • Latex Workshop (if desired - I recommend)

Display Theme

File/Preferences/Theme/Color Theme

to change the display theme. Play around and see what you like.

Command Palette

  • CTRL-SHFT-P opens the command palette.
  • Find “Select Python Interpreter” and make sure that your installation of python has been detected.

File/Open Folder

  • File/Open Folder and browse to find a folder in which you want to work.
  • Click Pages icon on left if necessary to see a File Explorer.

Terminal/New Terminal

  • Terminal/New Terminal to get a terminal (command prompt).
  • Command palette and “Terminal: Select Default Profile” if you want a different type of terminal window (e.g., PowerShell instead of Command Prompt).
  • As a test, execute
  pip install wrds

File/New File

  • Open a text file. Save as test.txt
  • Open another text file. Save as test.md
  • Open another text file. Save as test.tex
  • Open a python file. Save as test.py
  • Open a Jupyter notebook. Save as test.ipynb

Text and Markdown Files

  • In the .txt file, type some text and save.
  • In the .md file, type the following
  # A Header
  Some text


  $$\pi = \Sigma^{-1}\iota$$

  • Then try Render PDF, Render HTML, Render DOCX

LaTex

In the .tex file, you can type the following and render. It compiles to a pdf if you have TeX Live or tinytex installed. I recommend uninstalling miktex and installing tinytex. But that is outside the scope of our course.

  \documentclass{article}
  \begin{document}
  Some text
  \begin{equation}
    \pi = \Sigma^{-1}\iota
  \end{equation}
  \end{document}

Python Scripts

  • In the .py file, type
  import os
  dir_list = os.listdir()
  print(dir_list)
  • Save the .py file (File/Save or CTRL-S).
  • In the terminal, execute
  python test.py

Jupyter Notebooks

  • Jupyter notebooks consist of cells. They can be executed in any order.
  • Cells are markdown, code, or raw.
  • Cells can be added from the toolbar or by popups below cells. They can be changed from one type to another from the cell menu.
  • Cells can be executed by point-and-click or by CTRL-SHFT.
  • Create a markdown cell like the .md file and execute.
  • Create a code cell like the .py file and execute.

ChatGPT

  • Click the ChatGPT (Bito) icon in the left toolbar.
  • Submit the message ‘write python code to list all of the files in a directory’

GIT

  git clone <repo url>
  git pull origin main
  git add . 
  git commit -m "<some message>"
  git push origin main

Cloning Repos

Google Colab

  • In a browser, visit https://colab.research.google.com/.
  • To use colab, you need to sign in from a google account. Colab is not necessary for this course, so this is optional.
  • Once signed in, you should automatically be prompted to open a notebook. If not, use File/Open Notebook.
  • Select github and enter wesm/pydata-book. You can open any of the notebooks from the repo in colab and execute them there.
  • You can also create and save your own notebooks to your google drive.